package com.ciban.smarthome.module.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.TextView;

import com.ciban.smarthome.R;
import com.ciban.smarthome.module.ui.base.BaseActivity;
import com.ciban.smarthome.module.ui.adapter.IconChooseAdapter;

public class IconChooseActivity extends BaseActivity {
	private GridView gv_icons;
	private IconChooseAdapter adapter;

	private String[] ids;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_icons);

		ids = getIntent().getStringArrayExtra("ids");

		findViews();
	}

	private void findViews() {
		((TextView) findViewById(R.id.title)).setText("图标选择");

		gv_icons = (GridView) findViewById(R.id.scene_icon_choose_gv);
		adapter = new IconChooseAdapter(this, ids);
		gv_icons.setAdapter(adapter);

		setListeners();
	}

	private void setListeners() {
		gv_icons.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int position, long arg3) {
				Intent data = new Intent();
				data.putExtra("path", (String) adapter.getItem(position));
				setResult(RESULT_OK, data);
				finish();
			}
		});

	}
}
